package cn.tm.liu.mode.composite.demo1;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Marvin.L
 * @description
 * @date 2022.04.09 14.28
 */
public class Employee {
    private String name;
    private String dept;
    private int salary;
    private List<Employee> subordinates;

    //构造函数
    public Employee(String name, String dept, int sal) {
        this.name = name;
        this.dept = dept;
        this.salary = sal;
        subordinates = new ArrayList<Employee>();
    }

    public void add(Employee e) {
        subordinates.add(e);
    }

    public void remove(Employee e) {
        subordinates.remove(e);
    }

    public List<Employee> getSubordinates() {
        return subordinates;
    }

    public void print() {
        System.out.println(this);
        if (this.getSubordinates().isEmpty())
            return;
        else
            for (Employee employee : this.getSubordinates()) {
                employee.print();
            }
    }

    public String toString() {
        return ("Employee :[ Dept : " + String.format("%-15s", dept) + "Same : " + String.format("%-15s", name)
                + "Salary :" + String.format("%10d", salary) + " ]");
    }
}
